﻿using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace mkrpt
{
    class KesinKayit:MakeReport
    {
        public KesinKayit()
        {
            Doc = new Document(new Rectangle(842f, 595f));
            CreateOrcheckFolder(Application.StartupPath + "\\Report");
            Fs = new FileStream(Application.StartupPath + "\\Report\\OnKayitReport.pdf", FileMode.Create, FileAccess.Write, FileShare.Write);
        }
        void CreateOrcheckFolder(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
        public override void Printreport(DataGridView aGridView,string title, int rowCount, params int[] column)
        {
            PdfWriter.GetInstance(Doc, Fs);
            APTable = new PdfPTable(column.Count());
            //actual width of table in points
            APTable.TotalWidth = 800f;
            //fix the absolute width of the table
            APTable.LockedWidth = true;
            //relative col widths in proportions - 1/3 and 2/3
            var widths = new float[] { 3f, 3f ,5f,3f,6f,3f,4f,3f,4f};
            APTable.SetWidths(widths);
            APTable.HorizontalAlignment = 0;
            //leave a gap before and after the table
            APTable.SpacingBefore = 30f;
            APTable.SpacingAfter = 20f;
            APCell = new PdfPCell(new Phrase(title));
            APCell.Colspan = aGridView.ColumnCount;
            APCell.Border = 0;
            APCell.HorizontalAlignment = 1;
            APCell.VerticalAlignment = 1;
            APTable.AddCell(APCell);
            for (int i = 0; i < rowCount; i++)
            {
                foreach (var j in column)
                {
                    //MessageBox.Show(Convert.ToString(aGridView[j, i].Value));
                    APTable.AddCell(Convert.ToString(aGridView[j, i].Value));
                }
            }
            Doc.Open();
            Doc.AddHeader("Report", "");
            Doc.Add(new Phrase("Report"));
            Doc.Add(APTable);
            Doc.Close();
        }
    }
}
